const db = uniCloud.database();
const _ = db.command;

exports.main = async (event, context) => {
  try {
    // 查询轮播图数据，按排序字段升序排列
    const result = await db.collection('banners')
      .where({
        status: true // 只查询启用状态的轮播图
      })
      .orderBy('sort', 'asc')
      .get();
    
    return {
      code: 0,
      message: '获取轮播图成功',
      data: result.data
    };
  } catch (error) {
    console.error('获取轮播图失败:', error);
    return {
      code: -1,
      message: '获取轮播图失败',
      error: error.message
    };
  }
};